<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  UserMapper: lenovo
  Date: 2019-06-25
  Time: 15:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
    <div id="root">

        <Modal title="添加用户信息" v-model="showhidess" @on-ok="insert">
            <i-form :label-width="80">
                <form-item label="姓名">
                    <i-input v-model="user.anames"></i-input>
                </form-item>
                <form-item label="账号">
                    <i-input v-model="user.account"></i-input>
                </form-item>
                <form-item label="密码">
                    <i-input v-model="user.password"></i-input>
                </form-item>
                <form-item label="性别">
                    <Radio-Group v-model="user.agender">
                        <Radio :label="1">
                            <Icon type="md-male"></Icon>
                            <span>男</span>
                        </Radio>
                        <Radio :label="2">
                            <Icon type="md-female"></Icon>
                            <span>女</span>
                        </Radio>
                    </Radio-Group>
                </form-item>
                <form-item label="年龄">
                    <i-input type="number" v-model="user.aage"></i-input>
                </form-item>
                <form-item label="手机号">
                    <i-input type="number"  v-model="user.phone"></i-input>
                </form-item>
                <form-item label="生日">
                    <date-picker v-model="asd" v-model="user.birthday"  format="yyyy-MM-dd"/>
                </form-item>
                <%--<form-item label="基本工资">--%>
                    <%--<i-input v-model="user.moeny" ></i-input>--%>
                <%--</form-item>--%>
                <form-item label="状态">
                        <i-input disabled v-model="states"></i-input>
                </form-item>
                <form-item label="职位">
                    <i-select  v-model="user.positionidss">
                        <i-option v-for="item in userTypes" v-if="item.id!=1" :value="item.id">{{item.posi}}</i-option>
                    </i-select>
                </form-item>
                <form-item label="部门">
                    <i-select  v-model="user.bumenname">
                        <i-option v-for="item in bumen" :value="item.bumenname">{{item.bumenname}}</i-option>
                    </i-select>
                </form-item>
            </i-form>
        </Modal>








        <Modal title="修改用户信息" v-model="showhides" @on-ok="updatesa">
            <i-form :label-width="80">
                <form-item label="姓名">
                    <i-input v-model="user.anames"></i-input>
                </form-item>
                <form-item label="账号">
                    <i-input disabled v-model="user.account"></i-input>
                </form-item>
                <form-item label="性别">
                    <Radio-Group  v-model="user.agender">
                        <Radio :label="1">
                            <Icon type="md-male"></Icon>
                            <span>男</span>
                        </Radio>
                        <Radio :label="2">
                            <Icon type="md-female"></Icon>
                            <span>女</span>
                        </Radio>
                    </Radio-Group>
                </form-item>
                <form-item label="年龄">
                    <i-input type="number" v-model="user.aage"></i-input>
                </form-item>
                <form-item label="手机号">
                    <i-input type="number"  v-model="user.phone"></i-input>
                </form-item>
                <form-item label="生日">
                    <date-picker v-model="asd" v-model="user.birthday"  format="yyyy-MM-dd"/>
                </form-item>
                <%--<form-item label="基本工资">--%>
                    <%--<i-input v-model="user.moeny" ></i-input>--%>
                <%--</form-item>--%>
                <%--<form-item label="职位">--%>
                    <%--<i-select  v-model="user.positionidss">--%>
                        <%--<i-option v-for="item in userTypes" v-if="item.id!=1" :value="item.id">{{item.posi}}</i-option>--%>
                    <%--</i-select>--%>
                <%--</form-item>--%>
            </i-form>
        </Modal>




        <shiro:hasPermission name="users:add">
            <Row style="margin-top: 20px;margin-bottom: 10px">
                <i-Col offset="1">
                    <i-button type="primary" @click="insertasd">添加用户</i-button>
                </i-Col>
            </Row>
        </shiro:hasPermission>



        <Row  style="margin-top: 10px;margin-bottom: -10px">
            <i-col>
                <i-form :label-width="80" :inline="true">
                    <form-item label="姓名">
                       <i-input v-model="users.anames"></i-input>
                    </form-item>
                    <form-item label="手机号">
                        <i-input v-model="users.phone"></i-input>
                    </form-item>
                    <form-item label="职位">
                        <i-select v-model="users.posi" style="width: 200px">
                            <i-option value="0">请选择</i-option>
                            <i-option v-for="item in userType" :value="item.posi">{{item.posi}}</i-option>
                        </i-select>
                    </form-item>
                    <form-item label="状态">
                        <i-select v-model="users.state">
                            <i-option value="0">请选择</i-option>
                            <i-option value="1">在岗</i-option>
                            <i-option value="2">停职</i-option>
                        </i-select>
                    </form-item>
                        <i-button type="primary" icon="ios-search" @click="seachr">查询</i-button>
                </i-form>
            </i-col>
        </Row>
        <Row style="margin-left: 20px;margin-right: 20px">
            <i-col>
                <i-table :data="datas" :columns="columnss" border>
                    <template slot="caozuo" slot-scope="{row}">
                        <shiro:hasPermission name="users:upd">
                             <i-button size="small" v-if="row.remark!=0" type="primary" @click="updates(row)" >修改</i-button>
                        </shiro:hasPermission>
                        <%--<shiro:hasPermission name="user:sqaupd">--%>
                            <%--<i-button v-if="row.remark!=0" size="small" type="info">授权</i-button>--%>
                        <%--</shiro:hasPermission>--%>

                        <%--<i-button size="small" title="查看该用户所拥有的权限" type="warning">查看</i-button>--%>

                        <shiro:hasPermission name="users:zgtz">
                            <%--<i-button v-if="row.state==1&&row.remark!=0" @click="gangwei(row,2)" size="small" type="default">停职</i-button>--%>
                            <%--<i-button v-if="row.state==2&&row.remark!=0" @click="gangwei(row,1)" size="small" type="text">在岗</i-button>--%>
                        </shiro:hasPermission>
                </template>
                <template slot="gongzuozhao" slot-scope="{row}">
                    <img style="border-radius: 100%" :src="row.img" width="25px" height="25px" alt=""/>
                </template>
                    <template slot="agender" slot-scope="{row}">
                        <span>{{row.agender==1?"男":"女"}}</span>
                    </template>
                    <template slot="zhuangtai" slot-scope="{row}">
                        <%--<span>{{row.state==1?"在岗":"停职"}}</span>--%>
                            <%--<i-switch v-if="row.state==1" :value="true" />--%>
                            <%--<i-switch v-if="row.state==2"/>--%>
                            <i-switch v-if="row.remark!=0" :value="row.zs" @on-change="onchangestate(row)"/>
                    </template>
                </i-table>
            </i-col>
        </Row>
    </div>
    <script>
        let _this = null;
        new Vue({
            el:"#root",
            data:{
                showhidess:false,
                showhides:false,
                datas:[],
                columnss:[
                    {
                        title:"姓名",
                        key:"anames"
                    },
                    {
                        title:"工作照",
                        slot:"gongzuozhao"
                    },
                    {
                        title:"账号",
                        key:"account"
                    },
                    // {
                    //     title:"密码",
                    //     key:"password"
                    // },
                    {
                        title:"性别",
                        key:"agender",
                        slot:"agender",
                        sortable:true
                    },{
                        title:"年龄",
                        key:"aage",
                        sortable:true
                    },{
                        title:"手机号",
                        key:"phone"
                    },{
                        title:"生日",
                        key:"birthday",
                        sortable:true
                    },{
                        title:"职位",
                        key:"posi"
                    },{
                        title:"状态",
                        key:"state",
                        slot:"zhuangtai"
                    },{
                        title:"部门",
                        key:"bumenname"
                    },{
                        title:"操作",
                        width:"220",
                        slot:"caozuo"
                    }
                ],
                states:"在岗",
                asd:"1999-1-1",
                user:{
                    agender:1
                },
                userType:[],
                userTypes:[],
                users:{},
                asdadasd:1,
                bumen:[]
            },
            methods:{
        // /user/updsUpdateUser
                seachr(){
                    var obj = {};
                    Object.assign(obj,this.users)
                    if(obj.posi=="0"){
                        obj.posi="";
                    }
                    if(obj.state==0){
                        obj.state="";
                    }
                    axios.get("/users/userAll",{
                        params:obj
                    }).then(({data})=>{
                        this.datas = data.obj;
                        for (let i = 0; i < this.datas.length; i++) {
                            if(this.datas[i].state==1){
                                this.datas[i].zs = true;
                            }else{
                                this.datas[i].zs = false;
                            }
                        }
                    })
                },
                seachrType(){
                    axios.get("/users/userType").then(({data})=>{
                        this.userType = data.obj;
                        this.userTypes = data.obj;
                    })
                },
                insert(){
                    // if(this.user.aname==null){
                    //     iview.Message.warning("请输入姓名!");
                    //     return;
                    // }
                    // if(this.user.account==null){
                    //     iview.Message.warning("请输入账号!");
                    //     return;
                    // }
                    // if(this.user.password==null){
                    //     iview.Message.warning("请输入密码!");
                    //     return;
                    // }
                    // if(!nl(this.user.agender<=17)){
                    //     iview.Message.warning("请输入18以上的年龄!");
                    //     return;
                    // }
                    // var yanzheng = /^1[3|5|7|8|9]\d{9}$/;
                    //  if(!yanzheng.test(this.user.phone)){
                    //     iview.Message.warning("请输入正确的手机号!");
                    //     return;
                    // }
                        this.user.birthday =  moment(this.user.birthday).format("YYYY-MM-DD")
                        axios.post("/users/insert",this.user).then(({data})=> {
                            iview.Message.info(data.msg);
                            _this.seachr();
                            _this.user = {};
                        });
                },
                updatesa(){
                    this.user.birthday =  moment(this.user.birthday).format("YYYY-MM-DD")
                    axios.post("/user/updsUpdateUser",this.user).then(({data})=> {
                        iview.Message.info(data.msg);
                        _this.seachr();
                        _this.user = {};
                        _this.asdadasd = _this.user.aage;
                    });
                },
                insertasd(){
                    this.titles = "添加用户信息";
                    this.showhidess = true;
                },
                updates(row){
                    this.titles = "修改用户信息";
                    Object.assign(this.user,row)
                    this.showhides = true;
                },
                gangwei(row,number){
                    axios.post("/users/updateGangwei?id="+number+"&ids="+row.id).then(({data})=>{
                        iview.Message.info(data.msg);
                        _this.seachr();
                    })
                },
                bumennames(){
                    axios.post("/users/bumenMapper").then(({data})=>{
                       _this.bumen = data.obj;
                    })
                },
                onchangestate(row){
                    if(row.zs){
                        this.gangwei(row,2);
                    }else{
                        this.gangwei(row,1);
                    }
                }
             },
            mounted(){
                this.seachr();
                this.seachrType();
                this.bumennames();
            },
            created(){
                _this = this;
            }
        })
    </script>
</body>
</html>
